package xin.marcher.module.lifecycle.controller;

import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import xin.marcher.module.common.core.JsonResult;
import xin.marcher.module.common.core.PageResult;
import xin.marcher.module.lifecycle.domain.dto.ProductExpriConfigurationDTO;
import xin.marcher.module.lifecycle.domain.request.ProductExpriConfigurationRequest;
import xin.marcher.module.lifecycle.service.ProductExpriConfigurationService;

/**
 *
 */
@Slf4j
@RestController
@RequestMapping("/badIssuesResult")
public class ProductExpriConfigurationController {

    @Autowired
    private ProductExpriConfigurationService productExpriConfigurationService;

    /**
     * 新增考核配置信息
     *
     * @param request
     */
    @RequestMapping("/saveProductExpriConfiguration")
    public JsonResult<Long> saveProductExpriConfiguration(ProductExpriConfigurationRequest request) {
        try {
            Long count = productExpriConfigurationService.saveProductExpriConfiguration(request);
            return JsonResult.buildSuccess(count);
        } catch (Exception e) {
            log.error("system error: request={}", JSON.toJSONString(request), e);
            return JsonResult.buildError(e.getMessage());
        }
    }

    /**
     * 修改考核配置信息
     *
     * @param request
     * @return
     */
    @RequestMapping("/updateProductExpriConfiguration")
    public JsonResult<Boolean> updateProductExpriConfiguration(ProductExpriConfigurationRequest request) {
        try {
            Boolean result = productExpriConfigurationService.updateProductExpriConfiguration(request);
            return JsonResult.buildSuccess(result);
        } catch (Exception e) {
            log.error("system error: request={}", JSON.toJSONString(request), e);
            return JsonResult.buildError(e.getMessage());
        }
    }

    /**
     * 查询考核配置信息
     *
     * @param request
     * @return
     */
    @RequestMapping("/getProductExpriConfiguration")
    public JsonResult<ProductExpriConfigurationDTO> getProductExpriConfiguration(ProductExpriConfigurationRequest request) {
        try {
            ProductExpriConfigurationDTO result = productExpriConfigurationService.getProductExpriConfiguration(request);
            return JsonResult.buildSuccess(result);
        } catch (Exception e) {
            log.error("system error: request={}", JSON.toJSONString(request), e);
            return JsonResult.buildError(e.getMessage());
        }
    }


    /**
     * 分页查询考核配置信息
     *
     * @param request
     * @return
     */
    @RequestMapping("/queryProductExpriConfigurationByPage")
    public JsonResult<PageResult<ProductExpriConfigurationDTO>> queryProductExpriConfigurationByPage(ProductExpriConfigurationRequest request) {
        try {
            PageResult<ProductExpriConfigurationDTO> result = productExpriConfigurationService.queryProductExpriConfigurationByPage(request);
            return JsonResult.buildSuccess(result);
        } catch (Exception e) {
            log.error("system error: request={}", JSON.toJSONString(request), e);
            return JsonResult.buildError(e.getMessage());
        }
    }
}
